package com.think.archive.controller.api;

import com.think.archive.common.ResultBean;
import com.think.archive.dto.SysUserDto;
import com.think.archive.model.SysUser;
import com.think.archive.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api")
public class UserController {

    @Autowired
    SysUserService userService;

    @GetMapping("users")
    public ResultBean getUsers(){
        List<SysUserDto> userDtos =userService.selectAllUser();
        return ResultBean.createResultBySuccess(userDtos);
    }

    @PostMapping("saveUser")
    public ResultBean saveUser(SysUser user){
        return ResultBean.createResultBySuccess(userService.insertOrUpdateUser(user));
    }

    @PostMapping("deleteUser")
    public ResultBean deleteUser(int id){
        return ResultBean.createResultBySuccess(userService.deleteUser(id));
    }

    @RequestMapping("user/state/change")
    public ResultBean changeStatusUser(int id ,String status){
        int res=userService.changeStatusUser(id,status);
        return ResultBean.createResultBySuccess(res);
    }

}
